﻿using System;
using System.Web.UI.WebControls;

namespace ControlExplorer.samples.EditorCssClass
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (IsPostBack)
      {
        return;
      }

      InitSpread(FpSpread1);
      InitSpreadStyles(FpSpread1.Sheets[0]);
      this.FpSpread1.UseClipboard = false;
    }

    private void InitSpread(FarPoint.Web.Spread.FpSpread spread)
    {
      spread.CssClass = "spreadStyle";
      spread.UseClipboard = false;
    }

    private void InitSpreadStyles(FarPoint.Web.Spread.SheetView sheet)
    {
      sheet.Columns[0].Font.Underline = true;

      sheet.ColumnCount = 2;
      sheet.RowCount = 8;

      sheet.Columns[0].Width = 145;
      sheet.Columns[1].Width = 145;

      sheet.Rows.Default.Height = 26;

      sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle;

      sheet.SetClip(0, 0, 8, 1, "货币\n" + "日期\n" + "双精度\n" + "普通\n" + "整形\n" + "百分数\n" + "掩码\n" + "文本");

      FarPoint.Web.Spread.CurrencyCellType currcell = new FarPoint.Web.Spread.CurrencyCellType();
      currcell.EditorCssClass = "CurrencyStyle1";
      sheet.Cells[0, 1].CellType = currcell;
      sheet.Cells[0, 1].Value = 1234;

      FarPoint.Web.Spread.DateTimeCellType datecell = new FarPoint.Web.Spread.DateTimeCellType();
      datecell.EditorCssClass = "DateTimeStyle1";
      sheet.Cells[1, 1].CellType = datecell;
      sheet.Cells[1, 1].Value = DateTime.Now.ToShortDateString();

      FarPoint.Web.Spread.DoubleCellType dblcell = new FarPoint.Web.Spread.DoubleCellType();
      dblcell.EditorCssClass = "DoubleStyle1";
      sheet.Cells[2, 1].CellType = dblcell;
      sheet.Cells[2, 1].Value = 1234.5d;

      FarPoint.Web.Spread.GeneralCellType gencell = new FarPoint.Web.Spread.GeneralCellType();
      gencell.EditorCssClass = "GeneralStyle1";
      sheet.Cells[3, 1].CellType = gencell;
      sheet.Cells[3, 1].Value = "General";

      FarPoint.Web.Spread.IntegerCellType intcell = new FarPoint.Web.Spread.IntegerCellType();
      intcell.EditorCssClass = "IntegerStyle1";
      sheet.Cells[4, 1].CellType = intcell;
      sheet.Cells[4, 1].Value = 12;

      FarPoint.Web.Spread.PercentCellType pctcell = new FarPoint.Web.Spread.PercentCellType();
      pctcell.EditorCssClass = "PercentStyle1";
      sheet.Cells[5, 1].CellType = pctcell;
      sheet.Cells[5, 1].Value = 0.12;

      FarPoint.Web.Spread.RegExpCellType rgex = new FarPoint.Web.Spread.RegExpCellType();
      rgex.ValidationExpression = "^\\d{3}-\\d{2}-\\d{4}$";
      rgex.ErrorMessage = "SSN (ex, 123-45-6789)";
      rgex.EditorCssClass = "RegExpStyle1";
      sheet.Cells[6, 1].CellType = rgex;
      sheet.Cells[6, 1].Value = "123-45-6789";

      FarPoint.Web.Spread.TextCellType tcell = new FarPoint.Web.Spread.TextCellType();
      tcell.EditorCssClass = "TextStyle1";
      sheet.Cells[7, 1].CellType = tcell;
      sheet.Cells[7, 1].Value = "Text";

      sheet.Columns[0].Locked = true;
      sheet.LockBackColor = System.Drawing.Color.FromArgb(184, 184, 184);
    }
  }
}